/**
 * Copyright (c) Software Institute of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.transformation.editor.controller.editparts;

import org.eclipse.gef.EditPart;

import edu.pku.sei.modeler.edit.parts.AbstractEditPartFactory;
import edu.pku.sei.modeler.model.core.MetaElement;
import edu.pku.sei.modeler.model.structure.MetaDiagram;
import edu.pku.sei.modeler.model.structure.MetaShapeElement;
import edu.pku.sei.transformation.editor.controller.editparts.diagram.RuleDiagramEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.diagram.TransformationCommonDiagramEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.diagram.TransformationCompositeDiagramEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.CheckPointOperandEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.CommentConnectionEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.CompatibleEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.CompositionEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.ConnectionVariableEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.ConstraintConnectionEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.ControlFlowEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.DomainConnectionEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.ExtendEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.GoalRelationshipEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.ObjectFlowEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.OverrideEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.RuleInvokeEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.link.TransformationFormalParameterEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.AtomicTransformationEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.AtomicTransformationExecutionEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.CheckPointEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.CommentEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.CompositeTransformationEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.ConstraintEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.DecisionNodeEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.DescriptionEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.ExpressionEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.FinalNodeEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.ForkNodeEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.GraphicalDomainEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.InitialNodeEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.JoinNodeEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.MergeNodeEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.ModelTypeEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.ModelEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.ObjectVariableEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.PinEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.RuleEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.RuleExecutionEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.TestCaseEditPart;
import edu.pku.sei.transformation.editor.controller.editparts.node.TransformationExecutionEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.TransformationGoalEditpart;
import edu.pku.sei.transformation.editor.controller.editparts.node.TypedModelNodeEditpart;
import edu.pku.sei.transformation.editor.internal.TransformationEditorPaletteFactory;
import edu.pku.sei.transformation.editor.model.AtomicTransformation;
import edu.pku.sei.transformation.editor.model.Comment;
import edu.pku.sei.transformation.editor.model.CommentConnection;
import edu.pku.sei.transformation.editor.model.Compatiable;
import edu.pku.sei.transformation.editor.model.CompositeTransformation;
import edu.pku.sei.transformation.editor.model.DomainConnection;
import edu.pku.sei.transformation.editor.model.Expression;
import edu.pku.sei.transformation.editor.model.GraphicalDomain;
import edu.pku.sei.transformation.editor.model.ModelType;
import edu.pku.sei.transformation.editor.model.Rule;
import edu.pku.sei.transformation.editor.model.RuleInvoke;
import edu.pku.sei.transformation.editor.model.RuleOverride;
import edu.pku.sei.transformation.editor.model.TransformationComposition;
import edu.pku.sei.transformation.editor.model.TransformationExtend;
import edu.pku.sei.transformation.editor.model.TransformationFormalParameter;
import edu.pku.sei.transformation.editor.model.TypedModel;
import edu.pku.sei.transformation.editor.model.constraint.Constraint;
import edu.pku.sei.transformation.editor.model.constraint.ConstraintConnection;
import edu.pku.sei.transformation.editor.model.execution.AtomicTransformationExecution;
import edu.pku.sei.transformation.editor.model.execution.ControlFlow;
import edu.pku.sei.transformation.editor.model.execution.ControlNode;
import edu.pku.sei.transformation.editor.model.execution.Model;
import edu.pku.sei.transformation.editor.model.execution.ObjectFlow;
import edu.pku.sei.transformation.editor.model.execution.Pin;
import edu.pku.sei.transformation.editor.model.execution.RuleExecution;
import edu.pku.sei.transformation.editor.model.execution.TransformationExecution;
import edu.pku.sei.transformation.editor.model.goal.Description;
import edu.pku.sei.transformation.editor.model.goal.GoalRelationship;
import edu.pku.sei.transformation.editor.model.goal.TransformationGoal;
import edu.pku.sei.transformation.editor.model.test.CheckPoint;
import edu.pku.sei.transformation.editor.model.test.CheckPointOperand;
import edu.pku.sei.transformation.editor.model.test.TestCase;
import edu.pku.sei.transformation.editor.model.variable.ConnectionVariable;
import edu.pku.sei.transformation.editor.model.variable.ObjectVariable;

/**
 * @generated
 * 
 */
public class TransformationEditorEditpartFactory extends
		AbstractEditPartFactory {
	@Override
	public EditPart createEditPart(EditPart context, Object model) {
		EditPart part = null;
		if (model instanceof MetaDiagram) {
			MetaDiagram diagram = (MetaDiagram) model;
			if (TransformationEditorPaletteFactory.RULE_DIAGRAM.equals(diagram.getType())) {
				part = new RuleDiagramEditpart(diagram);
			} else if (TransformationEditorPaletteFactory.TRANSFORMATION_COMPOSITE_DIAGRAM.equals(diagram.getType())) {
				part = new TransformationCompositeDiagramEditpart(diagram);
			}/* else if (TransformationEditorPaletteFactory.RULE_DIAGRAM.equals(diagram.getType())) {
				part = new TransformationCommonDiagramEditpart(diagram);
			} else if (TransformationEditorPaletteFactory.TRANSFORMATION_STRUCTURE_DIAGRAM.equals(diagram.getType())) {
				part = new TransformationCommonDiagramEditpart(diagram);
			}  else {
				part = new DiagramEditPart((MetaDiagram) model);
			}*/
			else
				part = new TransformationCommonDiagramEditpart(diagram);
		} else if (model instanceof MetaShapeElement) {
			part = createEditPart(context, (MetaShapeElement) model);
		}
		part.setModel(model);
		return part;
	}

	public EditPart createEditPart(EditPart context, MetaShapeElement shape) {
		EditPart part = null;
		MetaElement content = shape.getModelElement();
		if (false) {
			part = null;
		}

		else if (content instanceof GraphicalDomain) {
			part = new GraphicalDomainEditpart(shape);

		} 

		else if (content instanceof ObjectVariable) {
			part = new ObjectVariableEditpart(shape);

		}
		else if (content instanceof ModelType) {
			part = new ModelTypeEditpart(shape);
		}
		else if (content instanceof AtomicTransformation) {
			part = new AtomicTransformationEditpart(shape);
		}
		else if (content instanceof CompositeTransformation) {
			part = new CompositeTransformationEditpart(shape);
		}
		else if (content instanceof TransformationFormalParameter) {
			part = new TransformationFormalParameterEditpart(shape);
		}
		else if (content instanceof Rule) {
			if (context instanceof RuleDiagramEditpart)
				part = new RuleEditpart(shape, RuleEditpart.MODE_NORMAL);
			else
				part = new RuleEditpart(shape, RuleEditpart.MODE_SIMPLE);
		}

		else if (content instanceof DomainConnection) {
			part = new DomainConnectionEditpart(shape);

		}

		else if (content instanceof ConnectionVariable) {
			part = new ConnectionVariableEditpart(shape);

		}

		else if (content instanceof RuleInvoke) {
			part = new RuleInvokeEditpart(shape);

		}

		else if (content instanceof TransformationExecution) {
			if (content instanceof AtomicTransformationExecution)
				part = new AtomicTransformationExecutionEditpart(shape);
			else
				part = new TransformationExecutionEditpart(shape);
		}
		
		else if (content instanceof RuleExecution) {
			part = new RuleExecutionEditpart(shape);
		}
		else if (content instanceof Model) {
			part = new ModelEditpart(shape);
		}
		
		else if (content instanceof TypedModel) {
//			if (context instanceof TransformationCompositeDiagramEditpart) {
				part = new TypedModelNodeEditpart(shape);
//			} else {
//				part = new TypedModelLinkEditpart(shape);
//			}
		}
		
		else if (content instanceof ObjectFlow) {
			part = new ObjectFlowEditpart(shape);
		}
		
		else if (content instanceof ControlFlow) {
			part = new ControlFlowEditpart(shape);
		} else if (content instanceof ControlNode) {
			switch (((ControlNode) content).getNodeType()) {
			case ControlNode.CONTROL_DECISION:
				part = new DecisionNodeEditpart(shape);
				break;
			case ControlNode.CONTROL_FINAL:
				part = new FinalNodeEditpart(shape);
				break;
			case ControlNode.CONTROL_FORK:
				part = new ForkNodeEditpart(shape);
				break;
			case ControlNode.CONTROL_INITIAL:
				part = new InitialNodeEditpart(shape);
				break;
			case ControlNode.CONTROL_JOIN:
				part = new JoinNodeEditpart(shape);
				break;
			case ControlNode.CONTROL_MERGE:
				part = new MergeNodeEditpart(shape);
				break;
			}
		} else if (content instanceof Pin) {
			return new PinEditpart(shape);
		} else if (content instanceof Expression) {
			return new ExpressionEditpart(shape);
		} else if (content instanceof Comment) {
			return new CommentEditpart(shape);
		} else if (content instanceof CommentConnection) {
			return new CommentConnectionEditpart(shape);
		} else if (content instanceof TransformationExtend) {
			return new ExtendEditpart(shape);
		} else if (content instanceof TransformationComposition) { 
			return new CompositionEditpart(shape);
		} else if (content instanceof RuleOverride) {
			return new OverrideEditpart(shape);
		} 
		//requirement
		else if (content instanceof TransformationGoal) {
			return new TransformationGoalEditpart(shape);
		} else if (content instanceof Constraint) {
			return new ConstraintEditpart(shape);
		} /*else if (content instanceof Refinement) {
			return new RefinementEditpart(shape);
		}*/ else if (content instanceof ConstraintConnection) {
			return new ConstraintConnectionEditpart(shape);
		} else if (content instanceof GoalRelationship) {
			return new GoalRelationshipEditpart(shape);
		} else if (content instanceof Description) {
			return new DescriptionEditpart(shape);
		}
		//test
		else if (content instanceof TestCase) {
			return new TestCaseEditPart(shape);
		} else if (content instanceof CheckPoint) {
			return new CheckPointEditpart(shape);
		} else if (content instanceof CheckPointOperand) {
			return new CheckPointOperandEditpart(shape);
		}
		//model type
		else if (content instanceof Compatiable) {
			return new CompatibleEditpart(shape);
		}
		else {
			part = super.createEditPart(shape);
		}
		return part;
	}
}
